package com.model;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;
import lombok.experimental.FieldNameConstants;
import lombok.extern.apachecommons.CommonsLog;

import javax.persistence.*;
import java.time.LocalDate;

/**
 * 爬取获得的info对象
 */
@Data
@Accessors(chain = true)
@ToString
@Table(name = "job_info")
@Entity
@ApiModel("招聘记录")
@FieldNameConstants
public class JobInfo {


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ApiModelProperty("id")
    private Long id;
    @Column(name = "recruit_title")
    @ApiModelProperty("招聘标题")
    private String recruitTitle;

    @Column(name = "recruit_info")
    @ApiModelProperty("招聘信息")
    private String recruitInfo;

    @Column(name = "company_info")
    @ApiModelProperty("公司信息")
    private String companyInfo;

    @Column(name = "recruit_type")
    @ApiModelProperty("招聘类型如:手机应用开发工程师 互联网软件开发工程师")
    private String recruitType;

    @Column(name = "recruit_key_word")
    @ApiModelProperty("招聘关键字(网站提供的关键字)")
    private String recruitKeyWord;

    @Column(name = "release_date")
    @ApiModelProperty("发布日期")
    private LocalDate releaseDate;

    @Column(name = "welfare_tip")
    @ApiModelProperty("福利标签")
    private String welfareTip;

    @Column(name = "wage")
    @ApiModelProperty("工资")
    private String wage;

    @Column(name = "min_wage")
    @ApiModelProperty("最小工资")
    private float minWage;

    @Column(name = "max_wage")
    @ApiModelProperty("最大工资")
    private float maxWage;

    @Column(name = "city")
    @ApiModelProperty("城市")
    private String city;

    @Column(name = "academic_requirements")
    @ApiModelProperty("学历要求")
    private String academicRequirements;

    @Column(name = "exp_range")
    @ApiModelProperty("经验要求")
    private String expRange;

    @Column(name = "recruitment_num")
    @ApiModelProperty("招聘人数")
    private String recruitmentNum;

    @Column(name = "key_words")
    @ApiModelProperty("关键字")
    private String keyWords;

    @Column(name = "company_name")
    @ApiModelProperty("公司名")
    private String companyName;

    @Column(name = "company_type")
    @ApiModelProperty("公司类型如:民营公司")
    private String companyType;

    @Column(name = "scale")
    @ApiModelProperty("公司规模:??-??人")
    private String scale;

    @Column(name = "industry")
    @ApiModelProperty("行业如:互联网/电子商务 计算机软件")
    private String industry;

    @Column(name = "work_address")
    @ApiModelProperty("上班地址")
    private String workAddress;

    @Column(name = "capture_url")
    @ApiModelProperty("爬虫获取的地址")
    private String captureUrl;

    // 经纬度
    @Column(name = "lng")
    private Double lng;
    @Column(name = "lat")
    private Double lat;

    @Column(name = "work_bug_id")
    @ApiModelProperty("由那个work任务获取的")
    private Long workBugId;

    @Column(name = "reptile_class")
    @ApiModelProperty("由那个class(type)获取的")
    private String reptileClass;

    @Column(name = "hashcode")
    @ApiModelProperty("去重编码")
    private String hashcode;

    @Column(name = "job_type")
    @ApiModelProperty("工种类型")
    private String jobType;

    // TODO 需要另外的已读表
//    @Column(name = "have_read")
//    private Boolean haveRead;



    // 日期展示
    @Transient
    private String releaseDateView;

    public void createHashcode() {
        if(this.companyName == null || this.recruitTitle == null || this.workBugId == null|| this.reptileClass == null) {
            return;
        }
        this.hashcode = String.format("TYPE:%s %d %d %d",
                this.reptileClass,
                this.recruitTitle.hashCode(),
                this.companyName.hashCode(),
                this.workAddress.hashCode()
        );
    }


}
